import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    uploadHistory: [],
    compressConfig: {
      maxFileSize: '10MB',
      supportedFormats: ['JPG', 'PNG', 'WebP', 'GIF'],
      maxWidth: 1920,
      maxHeight: 1080,
      defaultQuality: 0.8
    }
  },
  mutations: {
    ADD_UPLOAD_HISTORY(state, item) {
      state.uploadHistory.unshift(item)
      // 只保留最近20条记录
      if (state.uploadHistory.length > 20) {
        state.uploadHistory = state.uploadHistory.slice(0, 20)
      }
    },
    SET_COMPRESS_CONFIG(state, config) {
      state.compressConfig = { ...state.compressConfig, ...config }
    },
    CLEAR_HISTORY(state) {
      state.uploadHistory = []
    }
  },
  actions: {
    addUploadHistory({ commit }, item) {
      commit('ADD_UPLOAD_HISTORY', item)
    },
    setCompressConfig({ commit }, config) {
      commit('SET_COMPRESS_CONFIG', config)
    },
    clearHistory({ commit }) {
      commit('CLEAR_HISTORY')
    }
  },
  getters: {
    uploadHistory: state => state.uploadHistory,
    compressConfig: state => state.compressConfig
  }
}) 